import axios from 'axios'
//公共路径
let portUrl = " http://101.42.43.79/api";
//初始化时间
const initDate = (oldDate, full) => {
    var odate = new Date(oldDate);
    var year = odate.getFullYear();
    var month = odate.getMonth() < 9 ? '0' + (odate.getMonth() + 1) : odate.getMonth() + 1;
    var date = odate.getDate() < 10 ? '0' + odate.getDate() : odate.getDate();
    if (full == 'all') {
        var t = oldDate.split(" ")[0];
        return t.split('-')[0] + '年' + t.split('-')[1] + '月' + t.split('-')[2] + '日';
    } else if (full == 'year') {
        return year
    } else if (full == 'month') {
        return odate.getMonth() + 1
    } else if (full == 'date') {
        return date
    } else if (full == 'newDate') {
        return year + '年' + month + '月' + date + '日';
    }
}

const reqReware = (callback) => {
    let url = portUrl + '/reware'
    axios.get(url).then(result => {
        callback && callback(result.data)
    })
}

const reqLoveTotal = (callback) => {
    let url = portUrl + '/lovetotal'
    axios.get(url).then(result => {
        callback && callback(result.data)
    })
}

const reqAddLoveNum = (num, callback) => {
    let url = portUrl + `/addlovenum`
    axios({
        url,
        method: "post",
        data: {
            num
        }
    }).then(result => {
        callback && callback(result.data)
    })
}

const reqGetImgs = (callback) => {
    let url = portUrl + `/loveimgs`
    axios({
        url,
        method: "get",
    }).then(result => {
        callback && callback(result.data)
    })
}

const reqDeleteImg = (img,callback) => {
    let url = portUrl + `/deleteimg`
    axios({
        url,
        method: "post",
        data: {
            img
        }
    }).then(result => {
        callback && callback(result.data)
    })
}

const reqGetVideos = (callback) => {
    let url = portUrl + `/lovevideos`
    axios({
        url,
        method: "get",
    }).then(result => {
        callback && callback(result.data)
    })
}

const deleteVideo = (video,callback) => {
    let url = portUrl + `/deletevideo`
    axios({
        url,
        method: "post",
        data: {
            video
        }
    }).then(result => {
        callback && callback(result.data)
    })
}

const uploadMessage_lyb = (info,callback) => {
    let url = portUrl + `/uploadmessage_lyb`
    axios({
        url,
        method: "post",
        data: {
            info
        }
    }).then(result => {
        callback && callback(result.data)
    })
}

const Message_lyb = (callback) => {
    let url = portUrl + `/message_lyb`
    axios({
        url,
        method: "get",
    }).then(result => {
        callback && callback(result.data)
    })
}

const uploadMessage_gyw = (info,callback) => {
    let url = portUrl + `/uploadmessage_gyw`
    axios({
        url,
        method: "post",
        data: {
            info
        }
    }).then(result => {
        callback && callback(result.data)
    })
}

const Message_gyw = (callback) => {
    let url = portUrl + `/message_gyw`
    axios({
        url,
        method: "get",
    }).then(result => {
        callback && callback(result.data)
    })
}

const DeleteMessage_lyb = (info,callback) => {
    let url = portUrl + `/deleteMessage_lyb`
    axios({
        url,
        method: "post",
        data: info
    }).then(result => {
        callback && callback(result.data)
    })
}

const DeleteMessage_gyw = (info,callback) => {
    let url = portUrl + `/deleteMessage_gyw`
    axios({
        url,
        method: "post",
        data:info
    }).then(result => {
        callback && callback(result.data)
    })
}

const uploadOnineWrite = (info,callback) => {
    let url =portUrl + "/uploadOnineWrite"
    axios({
        url,
        method: "post",
        data:info
    }).then(result => {
        callback && callback(result.data)
    })
}

const reqGet_o_Writes = (callback) => {
    let url =portUrl + "/reqGet_o_Writes"
    axios({
        url,
        method: "get",
    }).then(result => {
        callback && callback(result.data)
    })
}

const reqGet_o_Inf = (info,callback) => {
    let url =portUrl + "/reqGet_o_Inf"
    axios({
        url,
        method: "post",
        data:info
    }).then(result => {
        callback && callback(result.data)
    })
}

const delete_o_Write = (info,callback) => {
    let url =portUrl + "/delete_o_Write"
    axios({
        url,
        method: "post",
        data:info
    }).then(result => {
        callback && callback(result.data)
    })
}



export {
    initDate,//设置时间
    reqReware,
    reqLoveTotal,
    reqAddLoveNum,
    reqGetImgs,
    reqDeleteImg,
    reqGetVideos,
    deleteVideo,
    uploadMessage_lyb,
    Message_lyb,
    uploadMessage_gyw,
    Message_gyw,
    DeleteMessage_lyb,
    DeleteMessage_gyw,
    uploadOnineWrite,
    reqGet_o_Writes,
    reqGet_o_Inf,
    delete_o_Write,
}
